Unit BDijitTextBoxUnit;

{$mode objfpc}{$H+}

Interface

Uses
  Classes, SysUtils, BDojoSessionUnit, BDijitFormWidgetUnit;

Type

{ BDijitTextBoxClass }

 BDijitTextBoxClass = Class(BDijitFormWidgetClass)
  Private
    bDisplayedValue: String;
    bLowerCase: Boolean;
    bMaxLength: Integer;
    bPlaceHolder: String;
    bProperCase: Boolean;
    bSelectOnClick: Boolean;
    bTrim: Boolean;
    bUpperCase: Boolean;
    Procedure SetDisplayedValue(aValue: String);
    Procedure SetLowerCase(aValue: Boolean);
    Procedure SetMaxLength(aValue: Integer);
    Procedure SetPlaceHolder(aValue: String);
    Procedure SetProperCase(aValue: Boolean);
    Procedure SetSelectOnClick(aValue: Boolean);
    Procedure SetTrim(aValue: Boolean);
    Procedure SetUpperCase(aValue: Boolean);
  Public
    //** For subclasses like ComboBox where the displayed value (ex: Kentucky)
    //** and the serialized value (ex: KY) are different, this represents the
    //** displayed value. Setting 'displayedValue' through set('displayedValue',
    //** ...) updates 'value', and vice-versa. Otherwise 'value' is updated from
    //**  displayedValue' periodically, like onBlur etc. TODO: move declaration
    //** to MappedTextBox? Problem is that ComboBox references displayedValue,
    //** for benefit of FilteringSelect. if the textbox is blank, what value
    //** should be reported
    Property DisplayedValue: String Read bDisplayedValue
      Write SetDisplayedValue;
    //** Converts all characters to lowercase if true. Default is false.
    Property LowerCase: Boolean Read bLowerCase Write SetLowerCase;
    //** HTML INPUT tag maxLength declaration.
    Property MaxLength: Integer Read bMaxLength Write SetMaxLength;
    //** Defines a hint to help users fill out the input field (as defined in
    //** HTML 5). This should only contain plain text (no html markup). allows
    //** IE to disallow focus, but Firefox cannot be disabled for mousedown
    //** events
    Property PlaceHolder: String Read bPlaceHolder Write SetPlaceHolder;
    //** Converts the first character of each word to uppercase if true.
    Property ProperCase: Boolean Read bProperCase Write SetProperCase;
    //** If true, all text will be selected when focused with mouse
    Property SelectOnClick: Boolean Read bSelectOnClick Write SetSelectOnClick;
    //** Removes leading and trailing whitespace if true. Default is false.
    Property Trim: Boolean Read bTrim Write SetTrim;
    //** Converts all characters to uppercase if true. Default is false.
    Property UpperCase: Boolean Read bUpperCase Write SetUpperCase;

    //** Converts the first character of each word to uppercase if true.
    Constructor Build(Const aSession: BDojoSessionClass;
      Const aJSType: String = ''); override;
End;

Implementation

{ BDijitTextBoxClass }

Procedure BDijitTextBoxClass.SetDisplayedValue(aValue: String);
Begin
  bDisplayedValue := aValue;
  SetConfig('displayedValue', aValue);
End;

Procedure BDijitTextBoxClass.SetLowerCase(aValue: Boolean);
Begin
  bLowerCase := aValue;
  SetConfig('lowercase', aValue);
End;

Procedure BDijitTextBoxClass.SetMaxLength(aValue: Integer);
Begin
  bMaxLength := aValue;
  SetConfig('maxLength', aValue);
End;

Procedure BDijitTextBoxClass.SetPlaceHolder(aValue: String);
Begin
  bPlaceHolder := aValue;
  SetConfig('placeHolder', aValue);
End;

Procedure BDijitTextBoxClass.SetProperCase(aValue: Boolean);
Begin
  bProperCase := aValue;
  SetConfig('propercase', aValue);
End;

Procedure BDijitTextBoxClass.SetSelectOnClick(aValue: Boolean);
Begin
  bSelectOnClick := aValue;
  SetConfig('selectOnClick', aValue);
End;

Procedure BDijitTextBoxClass.SetTrim(aValue: Boolean);
Begin
  bTrim := aValue;
  SetConfig('trim', aValue);
End;

Procedure BDijitTextBoxClass.SetUpperCase(aValue: Boolean);
Begin
  bUpperCase := aValue;
  SetConfig('uppercase', aValue);
End;

Constructor BDijitTextBoxClass.Build(Const aSession: BDojoSessionClass;
  Const aJSType: String);
Begin
  If aJSType = '' Then Inherited Build(aSession, 'dijit.form.TextBox')
  Else Inherited Build(aSession, aJSType)
End;

End.
